/**
 * 
 */
package saxena.mf.user;

import saxena.mf.utils.MFUtils;

/**
 * @author Ankur
 * 
 */
public class User {

	private String userID;
	private String userName;

	public static User registerUser(String userName) throws Exception {
		String uid = MFUtils.SHA1(userName);
		User u = new User(uid, userName);
		boolean chk = MFUtils.chkUser(u);
		if(chk){
			throw new Exception("User already present");
		}
		MFUtils.addUser(u);
		return u;
	}
	
	public static User loginUser(String userName)throws Exception {
		String uid = MFUtils.SHA1(userName);
		User u = new User(uid, userName);
		boolean chk = MFUtils.chkUser(u);
		if(!chk){
			throw new Exception("User does not exists");
		}
		return u;
	}
	
	private User(String userID, String userName){
		this.userID = userID;
		this.userName = userName;
	}

	
	public String getUserID() {
		return userID;
	}

	public String getUserName() {
		return userName;
	}

	public String toString(){
		return userID+"-"+userName;
	}
}
